package com.example.passport.service;


import com.example.common.dto.ListDto;
import com.example.common.dto.Pagination;
import com.example.passport.dto.WxUserDto;
import com.example.passport.entity.WxUser;
import com.example.passport.mapper.WxUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class WxUserService {


    @Resource
    WxUserMapper wxUserMapper;

    public int insertWxUser(WxUserDto wxUserDto) {
        WxUserDto by = wxUserMapper.findBy(wxUserDto);

        if (by == null) {
            return wxUserMapper.add(wxUserDto);
        }
        return 0;
    }

    public ListDto<WxUserDto> list(WxUserDto condition, Pagination pagination) {
        long total = wxUserMapper.count(condition);
        if (total == 0) {
            return new ListDto<>(new ArrayList<>(), pagination);
        }
        System.out.println("=====================>");
        System.out.println(pagination);
        pagination.setTotal(total);
        List<WxUserDto> list = wxUserMapper.list(condition, pagination);
        return new ListDto(list, pagination);
    }

}
